import React from "react";
import ReactDOM from "react-dom";
import ReactDOMClient from "react-dom/client";

import App from "./App.tsx";
import "./App.css";

import Taro from "./package";

// 应用配置
const config = {
  appId: "root",
  router: {},
  routes: [] as any[],
  pages: ["route/index"],
  window: {
    backgroundTextStyle: "light",
    navigationBarBackgroundColor: "#fff",
    navigationBarTitleText: "",
    navigationBarTextStyle: "black",
    navigationStyle: "custom",
  },
  requiredPrivateInfos: ["chooseLocation"],
  components: [
    "package/index",
    "package/ui/page/HomePage/index",
    "package/ui/layout/MobileLayout/index",
  ],
};

// 设置路由
config.routes = [
  {
    path: "/route/index",
    load: function load(context: any, params: any) {
      const page = import("./route/index");
      // const page = () => "ejfwoejfiwo";
      return [page, context, params];
    },
  },
];

// 兼容ReactDOMClient
Object.assign(ReactDOMClient, {
  findDOMNode: ReactDOM.findDOMNode,
  render: ReactDOM.render,
  unstable_batchedUpdates: ReactDOM.unstable_batchedUpdates,
});

// 创建React应用
const inst = Taro.createReactApp(App, React, ReactDOMClient, config);

console.log(inst);
// 创建hash历史记录
const history = Taro.createHashHistory({ window });
history;
// 处理应用挂载
// Taro.handleAppMount(config, history, "root");

// 创建路由
// Taro.createRouter(history, inst, config, "react");

console.log(Taro);

ReactDOMClient.createRoot(document.getElementById("root")!).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);
